package jp.tuyano.helo.server;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;

import jp.tuyano.core.PMF;
import jp.tuyano.helo.client.HeloService;
import jp.tuyano.helo.client.MyDataObject;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class HeloServiceImpl extends RemoteServiceServlet implements
        HeloService {

    private static final long serialVersionUID = 1L;

    public HeloServiceImpl() {}

    public List<MyDataObject> getAllEntities() {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        String query = "select from " + PersonalData.class.getName();
        @SuppressWarnings("unchecked")
        List<PersonalData> datas = (List<PersonalData>) pm.newQuery(query).execute();
        List<MyDataObject> result = new ArrayList<MyDataObject>();
        for (PersonalData data : datas) {
            result.add(new MyDataObject(data.getId(), data.getName(),
                    data.getMail(), data.getTel(),
                    data.getMemo()));
        }
        return result;
    }
}